package zhtt;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

/**
 * Created by mengxiaxia on 2017/4/22.
 */
public class SessionFactoryUtil3 {


        private static final String MYBATIS_CONFIG_PATH = "cfg/Configuration3.xml";

        private static InputStream is = null;

        private static SqlSessionFactory sqlSessionFactory2 = null;

        static {
            try{
                is = Resources.getResourceAsStream(MYBATIS_CONFIG_PATH);
                SqlSessionFactoryBuilder sqlSessionFactoryBuilder=new SqlSessionFactoryBuilder();
                Properties properties = new Properties();
                properties.put("jdbc.driverClassName","com.mysql.jdbc.Driver");
                properties.put("jdbc.url","jdbc:mysql://localhost:3306/test");
                properties.put("jdbc.url2","jdbc:mysql://localhost:3306/zhtt");
                properties.put("jdbc.user","root");
                properties.put("jdbc.pass","");
                properties.put("jdbc.table.auto","update");
                properties.put("jdbc.model.pack","zhtt.demo01");
//                InputStream in=SessionFactoryUtil3.class.getResourceAsStream("jdbc-mysql.properties");
//                properties.load(in);
//                in.close();
                /*这个是<environment id="test">*/
                sqlSessionFactory2 = sqlSessionFactoryBuilder.build(is, "zhtt");
            }catch (Exception e){
                e.printStackTrace();
            }

        }
        /**
         */
        private SessionFactoryUtil3(){};


        /**
         * @return SqlSessionFactory
         */
        public static SqlSessionFactory getSqlSessionFactoryIntance2(){

            return sqlSessionFactory2;

        }

        /**
         * @return SqlSession
         */
        public static SqlSession getSqlSessionIntance2() {
            return sqlSessionFactory2.openSession();
        }

}
